package com.suse.service.admin.cms.controller;

import com.suse.common.base.model.param.PageQueryParam;
import com.suse.common.config.response.ApiException;
import com.suse.common.config.response.R;
import com.suse.service.admin.cms.model.param.AdTypeSaveParam;
import com.suse.service.admin.cms.model.param.AdTypeUpdateParam;
import com.suse.service.admin.cms.service.AdTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 广告类型 前端控制器
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-17
 */
@Api(tags = "广告类型接口")
@RestController
@RequestMapping("/adType")
public class AdTypeController {

    @Resource
    private AdTypeService adTypeService;

    @ApiOperation(value = "获取广告类型列表")
    @PostMapping("/list")
    public R getAdTypeList() {
        return adTypeService.getAdTypeList();
    }

    @ApiOperation(value = "获取广告类型分页")
    @PostMapping("/page")
    public R getAdTypePage(@RequestBody PageQueryParam pageQueryParam) {
        return adTypeService.getAdTypePage(pageQueryParam);
    }

    @ApiOperation(value = "通过ID获取广告类型信息")
    @PostMapping("/info/{id}")
    public R getAdTypeInfo(@PathVariable("id") String id) {
        return adTypeService.getAdTypeInfo(id);
    }

    @ApiOperation(value = "添加广告类型")
    @PostMapping("/save")
    public R saveAdType(@Valid @RequestBody AdTypeSaveParam adTypeSaveParam) {
        return adTypeService.saveAdType(adTypeSaveParam);
    }

    @ApiOperation(value = "修改广告类型")
    @PutMapping("/update")
    public R updateAdType(@Valid @RequestBody AdTypeUpdateParam adTypeUpdateParam) {
        return adTypeService.updateAdType(adTypeUpdateParam);
    }

    @ApiOperation(value = "通过ID删除广告类型")
    @DeleteMapping("/remove/{id}")
    public R removeAdTypeById(@PathVariable("id") String id) {
        if (adTypeService.removeById(id)) {
            return R.success("删除成功");
        }else {
            throw new ApiException("删除失败！");
        }
    }

}

